/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rdb.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Bich Tran Van
 */
@Entity
@Table(name = "Subjects")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Subjects.findAll", query = "SELECT s FROM Subjects s"),
    @NamedQuery(name = "Subjects.findById", query = "SELECT s FROM Subjects s WHERE s.id = :id"),
    @NamedQuery(name = "Subjects.findBySuName", query = "SELECT s FROM Subjects s WHERE s.suName = :suName"),
    @NamedQuery(name = "Subjects.findByMinMark", query = "SELECT s FROM Subjects s WHERE s.minMark = :minMark"),
    @NamedQuery(name = "Subjects.findByMaxMark", query = "SELECT s FROM Subjects s WHERE s.maxMark = :maxMark")})
public class Subjects implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "Id")
    private Integer id;
    @Size(max = 50)
    @Column(name = "suName")
    private String suName;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "MinMark")
    private Double minMark;
    @Column(name = "MaxMark")
    private Double maxMark;
    @JoinTable(name = "Subject_Fac", joinColumns = {
        @JoinColumn(name = "subId", referencedColumnName = "Id")}, inverseJoinColumns = {
        @JoinColumn(name = "userId", referencedColumnName = "user_id")})
    @ManyToMany
    private List<Users> usersList;
    @JoinColumn(name = "suSemester", referencedColumnName = "Id")
    @ManyToOne
    private Semesters suSemester;
    @OneToMany(mappedBy = "subjectId")
    private List<Exams> examsList;

    public Subjects() {
    }

    public Subjects(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSuName() {
        return suName;
    }

    public void setSuName(String suName) {
        this.suName = suName;
    }

    public Double getMinMark() {
        return minMark;
    }

    public void setMinMark(Double minMark) {
        this.minMark = minMark;
    }

    public Double getMaxMark() {
        return maxMark;
    }

    public void setMaxMark(Double maxMark) {
        this.maxMark = maxMark;
    }

    @XmlTransient
    public List<Users> getUsersList() {
        return usersList;
    }

    public void setUsersList(List<Users> usersList) {
        this.usersList = usersList;
    }

    public Semesters getSuSemester() {
        return suSemester;
    }

    public void setSuSemester(Semesters suSemester) {
        this.suSemester = suSemester;
    }

    @XmlTransient
    public List<Exams> getExamsList() {
        return examsList;
    }

    public void setExamsList(List<Exams> examsList) {
        this.examsList = examsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Subjects)) {
            return false;
        }
        Subjects other = (Subjects) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rdb.entities.Subjects[ id=" + id + " ]";
    }
    
}
